package com.sky.controller.admin;

import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public Result addSetmeal(@RequestBody SetmealVO setmealVO) {
        setmealService.addSetmeal(setmealVO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult> pageSetmeal(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult setmealPage = setmealService.pageSetmeal(setmealPageQueryDTO);
        return Result.success(setmealPage);
    }

    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@RequestParam Long id, @PathVariable Integer status) {
        setmealService.updateSetmealStatus(id, status);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmeal(@PathVariable Long id) {
        SetmealVO setmeal = setmealService.querySetmealById(id);
        return Result.success(setmeal);
    }

    @PutMapping
    public Result<SetmealVO> updateSetmealById(@RequestBody SetmealVO setmealVO) {
        setmealService.updateSetmealById(setmealVO);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteSetmealByIds(Long[] ids) {
        setmealService.deleteSetmealByIds(ids);
        System.out.println("123");
        return Result.success();
    }
}
